from django.contrib.auth.models import AbstractUser
from django.db import models

from imagekit.models import ProcessedImageField
from imagekit.processors import ResizeToFill


class User(AbstractUser):
    nickname = models.CharField(max_length=30,  verbose_name='昵称')
    signature = models.CharField(max_length=128, blank=True, null=True, verbose_name='座右铭')
    gender = models.CharField(max_length=30, choices=(("male", "男"), ("female", "女")), default="female",
                              verbose_name="性别")
    identify = models.CharField(max_length=30, choices=(("student", "学生"), ("teacher", "教师"), ("company", "公司")),
                                default="学生", verbose_name='身份')
    avatar = ProcessedImageField(upload_to='avatar',
                                 default='avatar/default.png',
                                 verbose_name='头像',
                                 processors=[ResizeToFill(85, 85)])
    mobile = models.CharField(max_length=11, null=True, blank=True,verbose_name='联系电话')
    email = models.CharField(max_length=50, null=False)
    class Meta(AbstractUser.Meta):
        pass


class EmailVerifyRecord(models.Model):
    code = models.CharField(max_length=10, verbose_name="验证码")
    email = models.EmailField(max_length=50, verbose_name="邮箱")
    send_type = models.CharField(max_length=10, choices=(("register", "注册"), ("forget", "修改密码")))
    send_time = models.DateTimeField(auto_now_add=True)

    class Meta:
        verbose_name = "邮箱验证码"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.email+self.code
